package basicJava.enumType.enumType5;
/**
 * 实现接口
 * @author Administrator
 * 因为所有的枚举都是继承自Enum类，所以，不能再从其他的类继承
 * 所以只能通过实现接口的方式，来对其进行扩展
 */

public enum Color implements Behavior {
	RED("红色",1),GREEN("绿色",2),BLANK("白色",3),YELLOW("黄色",4);
	private String name;
	private int index;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getIndex() {
		return index;
	}
	public void setIndex(int index) {
		this.index = index;
	}
	/*
	 * Illegal modifier for the enum constructor; 
	 * only private is permitted
	 */
//	public Color(String name ,int index){
	private Color(String name ,int index){
		this.name = name;
		this.index = index;
	}
	//通过index寻找对应的name
	public static String getName(int index){
		for (Color color:Color.values()) {
			if (color.getIndex()==index) {
				return color.name;
			}
		}
		return null;
	}
	
	@Override
	public void print() {
		System.out.println("name is"+this.name);
	}
	@Override
	public String getInfo() {
		return name;
	}
	
}
